package com.bytecollege.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bytecollege.model.Aremark;

import com.bytecollege.vo.AremarkVo;
import com.bytecollege.vo.ArticleVo;
import com.bytecollege.vo.MyAreMarkVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName: AremarkMapper
 * @Description:
 * @Author: Sun
 * @Date: 2022/10/18 21:03
 */

@Mapper
public interface AremarkMapper extends BaseMapper<Aremark> {

    /**
     * 查找帖子对应的回复
     * @param page
     * @param wrapper
     * @return
     */
    @Select("select ar.aremark_content,ar.aremark_time,u.user_nickname,u.user_headphoto"+
            " from aremark ar" +
            "   left join user u" +
            "   on ar.user_id = u.user_id" +
            "   ${ew.customSqlSegment}"+
            "   order by ar.aremark_time desc")
    IPage<AremarkVo> getAremarkByArticleId(Page<AremarkVo> page,@Param("ew") Wrapper wrapper);

    @Select("select AreMark_Id, AreMark_Content , a.User_Id,AreMark_Time ,User_NickName ,Article_title from aremark left join user u on aremark.User_Id = u.User_Id left join article a on aremark.Article_Id = a.Article_Id where u.User_Id = #{userId}")
    List<MyAreMarkVO> getAremarkList(Page<MyAreMarkVO> page , @Param("userId") Integer userId);

}